<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>缴费信息列表</title>

    <style>
        .x-nav{padding:0 20px;position:relative;z-index:99;border-bottom:1px solid #e5e5e5;line-height:39px;height:39px;overflow:hidden}

        .layui-table-cell {
            height: 100%;
            max-width: 100%;
        }
    </style>
    <!--    解决layui复选框不居中显示的bug-->
    <style type="text/css">
        .layui-table-cell .layui-form-checkbox[lay-skin="primary"]{
            top: 50%;
            transform: translateY(-50%);
        }
    </style>
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>维修管理</cite></a>
              <a><cite>维修信息管理</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="layui-inline">
    <label class="layui-form-label">报修人</label>
    <div class="layui-input-inline">
        <input type="text" name="likeusername" id="likeusername" autocomplete="off" placeholder="请输入" class="layui-input">
    </div>
</div>
<div class="layui-inline">
    <label class="layui-form-label">维修员姓名</label>
    <div class="layui-input-inline">
        <input type="text" name="likerepairname" id="likerepairname" autocomplete="off" placeholder="请输入" class="layui-input">
    </div>
</div>
<div class="layui-inline">
    <label class="layui-form-label">维修设备名</label>
    <div class="layui-input-inline">
        <input type="text" name="likedevicename" id="likedevicename" autocomplete="off" placeholder="请输入" class="layui-input">
    </div>
</div>
<div class="layui-inline">
    <div class="layui-input-inline">
        <button class="layui-btn" id="searchBtn" lay-submit
                lay-filter="formDemo" data-type="reload" style="margin-left: 15px">
            <i class="layui-icon layui-icon-search"></i> 查询
        </button>
        <button class="layui-btn" id="reset">重置</button>
    </div>
</div>


<div class="layui-col-xs12">
    <button type="button" class="layui-btn" id="addBtn">
        <i class="layui-icon">&#xe608;</i> 添加
    </button>
    <table id="repairStreamTable" lay-filter="repairStreamTable" ></table>
</div>


<!--添加-->
<form id="addForm" class="layui-form" style="display:none;padding:10px 20px 0px 0px"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->

    <div class="layui-form-item">
        <label class="layui-form-label">维修设备名</label>
        <div class="layui-input-block">
            <input type="text" name="deviceName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="uploadFile1">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
        </div>
    </div>
    <input type="hidden" name="rsPhoto" id="ImageAdd" value=""/>
    <div class="layui-upload-list">
        　<img class="layui-upload-img" width="200px" height="100px" id="preShow1"/>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">报修描述</label>
        <div class="layui-input-block">
            <textarea name="device" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">地点</label>
        <div class="layui-input-block">
            <input type="text" name="place" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">创建时间</label>
        <div class="layui-input-block">
            <input type="text" name="createTime" class="layui-input" id="addDateCreateTime" autocomplete="off">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="addRepairStream">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
</form>

<!--修改-->
<form id="updateForm" lay-filter="updateForm" class="layui-form" style="display:none;padding:10px 20px 0px 0px"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
    <input type="hidden" name="id" id="id" >

    <div class="layui-form-item">
        <label class="layui-form-label">维修设备名</label>
        <div class="layui-input-block">
            <input type="text" name="deviceName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="uploadFile2">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
        </div>
    </div>
    <input type="hidden" name="rsPhoto" id="ImageUpdate" value=""/>
    <div class="layui-upload-list">
        　<img class="layui-upload-img" width="200px" height="100px" id="preShow2"/>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">报修描述</label>
        <div class="layui-input-block">
            <textarea name="device" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">地点</label>
        <div class="layui-input-block">
            <input type="text" name="place" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">创建时间</label>
        <div class="layui-input-block">
            <input type="text" name="createTime" class="layui-input" id="updateDateCreateTime" autocomplete="off">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="updateRepairStream">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
</form>

<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<link rel="stylesheet" href="layui/css/layui.css" type="text/css">
<script type="text/javascript">
    $(window).on('load',function() {
        let item = localStorage.getItem("code");
        if (item != 0) {
            window.location.href = "/login.jsp"
        }
    });
    layui.use(['element'], function(){
        var element=layui.element;
        element.init();
    });

    layui.use(["table","form","upload","layer","tree","laydate"],function() {
        var table = layui.table;
        var form = layui.form;
        var upload = layui.upload;
        var layer = layui.layer;
        var tree = layui.tree;
        var laydate=layui.laydate;

        //渲染table表格=====开始
        table.render({
            elem: '#repairStreamTable'
            ,page: true
            ,limit:5
            ,limits:[5,8,12]
            ,url: 'http://localhost:8888/hy-repair-stream/showAllRepairStream' //数据接口
            ,cols: [[ //表头
                {field: 'id',width:60,  title: '编号' }
                ,{field: 'deviceName', title: '维修设备名'}
                ,{field: 'device', title: '报修描述'}
                ,{field: 'rsPhoto', title: '照片'
                    ,templet:function(d){
                        return "<img src='"+d.rsPhoto+"' height='50'/>";
                    }
                }
                ,{field: 'repairName', title: '维修人员名称'}
                ,{field: 'place',width:150,  title: '维修地点'}
                ,{field: 'userName', title: '报修人'}
                ,{field: 'createTime', width:170, title: '创建时间',sort: true,}
                ,{field: 'state', title: '状态',
                    templet:function(d){
                        if(d.state==1){
                            return "待接单";
                        } else if(d.state==2){
                            return "已接单";
                        } else if(d.state==3){
                            return "待评价";
                        } else if(d.state==4){
                            return "已结束";
                        }else {
                            return "";
                        }
                    }
                }
                ,{field: 'evaluate', title: '评价',
                    templet:function(d){
                        if(d.evaluate==1){
                            return "满意";
                        }else if(d.evaluate==0){
                            return "不满意";
                        }else{
                            return "";
                        }
                    }
                }
                ,{title:"操作", width:300, align:'center', toolbar: '#barDemo'}
            ]]
        });

        // 给添加按钮增加弹出层---开始
        $("#addBtn").click(function(){
            layer.open({
                type:1,
                offset: 't',
                title:"添加报修信息",
                content:$("#addForm")
            });
        });
        //给添加按钮增加弹出层---结束

        //给添加表单增加监听事件---开始
        form.on("submit(addRepairStream)", function(data){
            //发出ajax请求，往数据库里面存储数据---开始
            $.ajax({
                url:"http://localhost:8888/hy-repair-stream/addRepairStream",
                data:data.field,
                dataType:"json",
                type:"post",
                success:function(res){
                    if(res.code==0){
                        //关闭弹出层
                        layer.closeAll();
                        layer.msg("添加成功！");
                        //刷新table表格
                        table.reload("repairStreamTable");
                        $("#addForm").css("display","none");

                    }
                }
            });
            //发出ajax请求，往数据库里面存储数据---结束
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //给添加表单增加监听事件---结束

        /*监听table表格上面的操作按钮====开始*/

        table.on("tool(repairStreamTable)",function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if(layEvent === 'del'){
                //调用confirm方法
                layer.confirm('是否确认删除？',function (ss) {
                    //发出ajax请求
                    $.ajax({
                        url: "http://localhost:8888/hy-repair-stream/deleteRepairStream",
                        data: "id="+data.id,
                        dataType: "json",
                        success: function (uyg) {
                            //提示删除成功，刷新table表格
                            layer.msg("删除成功");
                            table.reload("repairStreamTable");
                        }
                    });
                    layer.close(ss);
                });
            }else if(layEvent === 'edit') {
                //1.根据data获取到数据
                //2.把数据回显到修改的form表单中
                form.val("updateForm",data);
                //把from表单放入弹出层中显示出来
                layer.open({
                    type:1,
                    offset: 't',
                    title:"修改维修信息",
                    content:$("#updateForm")
                });
                $("#preShow2").attr('src','${pageContext.request.contextPath}/'+data.rsPhoto);
            }
        })

        /*监听table表格上面的操作按钮====结束*/

        //监听修改form的提交按钮===开始
        form.on('submit(updateRepairStream)', function(data){
            //发出ajax请求，往数据库里面存储数据---开始
            console.log(data);
            $.ajax({
                url:"http://localhost:8888/hy-repair-stream/updateRepairStream",
                data:data.field,
                dataType:"json",
                type:"post",
                success:function(res){
                    if(res.code==0){
                        //关闭弹出层
                        layer.closeAll();
                        layer.msg("修改成功！");
                        //刷新table表格
                        table.reload("repairStreamTable");
                        $("#updateForm").css("display","none");
                    }
                }
            });
            //发出ajax请求，往数据库里面存储数据---结束
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //监听修改学生的提交按钮===结束

        //日期时间选择器

        laydate.render({
            elem: '#addDateCreateTime'
            ,type: 'datetime'
        });


        laydate.render({
            elem: '#updateDateCreateTime'
            ,type: 'datetime'
        });

        upload.render({
            elem: '#uploadFile1' //绑定元素
            ,accept: "file"
            ,url: '${pageContext.request.contextPath}/hy-repair-stream/uploadImage' //上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#preShow1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                console.log(res)
                //上传完毕回调,需要把上传到服务器的文件名放到form表单里面。
                $("#ImageAdd").val(res.msg);
            }
        });
        upload.render({
            elem: '#uploadFile2' //绑定元素
            ,accept: "file"
            ,url: '${pageContext.request.contextPath}/hy-repair-stream/uploadImage' //上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#preShow2').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                console.log(res)
                //上传完毕回调,需要把上传到服务器的文件名放到form表单里面。
                $("#ImageUpdate").val(res.msg);
            }
        });

    })


    $('#searchBtn').on('click', function () {
        layui.use("table",function() {
            let table = layui.table;
            table.render({
                elem: '#repairStreamTable'
                ,page: true
                ,limit:5
                ,limits:[5,8,12]
                ,where: {
                    likeusername:$('#likeusername').val(),
                    likerepairname:$("#likerepairname").val(),
                    likedevicename:$("#likedevicename").val()
                }
                ,url: 'http://localhost:8888/hy-repair-stream/showAllRepairStream' //数据接口
                ,cols: [[ //表头
                    {field: 'id',width:60,  title: '编号' }
                    ,{field: 'deviceName', title: '维修设备名'}
                    ,{field: 'device', title: '报修描述'}
                    ,{field: 'rsPhoto', title: '照片'
                        ,templet:function(d){
                            return "<img src='"+d.rsPhoto+"' height='50'/>";
                        }
                    }
                    ,{field: 'repairName', title: '维修人员名称'}
                    ,{field: 'place',width:150,  title: '维修地点'}
                    ,{field: 'userName', title: '报修人'}
                    ,{field: 'createTime', width:170, title: '创建时间',sort: true,}
                    ,{field: 'state', title: '状态',
                        templet:function(d){
                            if(d.state==1){
                                return "待接单";
                            } else if(d.state==2){
                                return "已接单";
                            } else if(d.state==3){
                                return "待评价";
                            } else if(d.state==4){
                                return "已结束";
                            }else {
                                return "";
                            }
                        }
                    }
                    ,{field: 'evaluate', title: '评价',
                        templet:function(d){
                            if(d.evaluate==1){
                                return "满意";
                            }else if(d.evaluate==0){
                                return "不满意";
                            }else{
                                return "";
                            }
                        }
                    }
                    ,{title:"操作", width:300, align:'center', toolbar: '#barDemo'}
                ]]
            });
        });
    });
    $("#reset").click(function(){
        $("input[type='text']").prop("value","");
    });


</script>

<script type="text/html" id="barDemo">
    <button type="button" class="layui-btn  layui-btn-sm"><i class="layui-icon" lay-event="edit"></i></button>
    <button type="button" class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon" lay-event="del"></i></button>
</script>
</body>
</html>
